import {
  $stopWuxRefresher
} from '../../dist/index'

Page({
  data: {
    jiazai: true,
    current: '0',
    content: [],
    name: wx.getStorageSync('nickName'),
    inputValue: "",
    id: 0,
    placeholder: '',
    host: wx.getStorageSync('host'),
    windowHeight: 0,
    curPage: 1,
    login: false,
    bottom: false,
    ii: [],
    sou: '',
    kong: true
  },
  onLoad(options) {
    var that = this
    var url = wx.getStorageSync('url');
    wx.getSetting({
      success: res => {
        console.log(res)
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success: res => {
                if (res.userInfo.avatarUrl != wx.getStorageSync('headPortrait'))
                wx.request({
                  url: url + "/v1/user/head_portrait",
                  data: {
                    headPortrait: res.userInfo.avatarUrl
                  },
                  method: "put",
                  header: {
                    'content-type': 'application/json',
                    'authorization': wx.getStorageSync('authorization')
                  },
                  success: function (res) {
                    wx.setStorageSync('headPortrait', res.userInfo.avatarUrl);
                  }
                })
              if (res.userInfo.nickName != wx.getStorageSync('nickName'))
                wx.request({
                  url: url + "/v1/user/nick_name",
                  data: {
                    nickName: res.userInfo.nickName
                  },
                  method: "put",
                  header: {
                    'content-type': 'application/json',
                    'authorization': wx.getStorageSync('authorization')
                  },
                  success: function (res) {
                    wx.setStorageSync('nickName', res.userInfo.nickName);
                  }
                })
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)

              }
            }
          })
        } else {
          wx.reLaunch({
            url: '/pages/login/index',
          })
        }
      }
    })
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          windowHeight: res.windowHeight - 82 + "px",
        })
      }
    })
    wx.login({
      success: res => {
        wx.request({
          url: url + '/v1/token/wx',
          data: {
            code: res.code
          },
          method: "GET",
          header: {
            'content-type': 'application/json'
          },
          success: function(res) {
            var openid = res.data.data.mpTokenResponse.openId
            wx.setStorageSync('openid', openid);
            wx.request({
              url: url + '/v1/token/wx',
              data: {
                openId: openid
              },
              method: "POST",
              header: {
                'content-type': 'application/json',
                'openid': wx.getStorageSync('openid')
              },
              success: function(res) {
                if (res.data.data.code == 0) {
                  wx.setStorageSync('allid', res.data.data.mpUserLoginResponse.id);
                  wx.setStorageSync('nickName', res.data.data.mpUserLoginResponse.nickName);
                  wx.setStorageSync('headPortrait', res.data.data.mpUserLoginResponse.headPortrait);
                  wx.setStorageSync('schoolName', res.data.data.mpUserLoginResponse.schoolName);
                  wx.setStorageSync('authorization', res.data.authorization);
                  that.setData({
                    content: '',
                    jiazai: true,
                  })
                  wx.request({
                    url: url + '/v1/article',
                    data: {},
                    method: "get",
                    header: {
                      'content-Type': 'application/json',
                      'authorization': wx.getStorageSync('authorization'),
                      'openid': wx.getStorageSync('openid')
                    },
                    success: function(res) {
                      var list = []
                      list = res.data.data.mpArticleResponses
                      for (var i = 0; i < list.length; i++) {
                        list[i].image = list[i].image.split(",").slice(0, 3)
                      }
                      for (var j = 0; j < list.length; j++) {
                        if (list[j].type == 1) {
                          list[j].ctype = '求助'
                        } else if (list[j].type == 2) {
                          list[j].ctype = '闲置'
                        } else if (list[j].type == 3) {
                          list[j].ctype = '兼职'
                        } else if (list[j].type == 4) {
                          list[j].ctype = '租房'
                        } else if (list[j].type == 5) {
                          list[j].ctype = '寻物'
                        } else if (list[j].type == 6) {
                          list[j].ctype = '招领'
                        } else if (list[j].type == 7) {
                          list[j].ctype = '投稿'
                        } else if (list[j].type == 8) {
                          list[j].ctype = '表白'
                        }
                      }
                      that.setData({
                        content: list,
                        jiazai: false,
                      })
                      if (res.data.code == 10008) {

                        wx.request({
                          url: url + '/v1/token/wx',
                          data: {
                            openId: wx.getStorageSync('openid')
                          },
                          method: "POST",
                          header: {
                            'content-Type': 'application/json',
                            'openid': wx.getStorageSync('openid'),
                          },
                          success: function(res) {

                            wx.setStorageSync('nickName', res.data.data.mpUserLoginResponse.nickName);
                            wx.setStorageSync('headPortrait', res.data.data.mpUserLoginResponse.headPortrait);
                            wx.setStorageSync('allid', res.data.data.mpUserLoginResponse.id);
                            wx.setStorageSync('schoolName', res.data.data.mpUserLoginResponse.schoolName);
                            wx.setStorageSync('authorization', res.data.authorization);
                            that.setData({
                              content: '',
                              jiazai: true,
                            })
                            wx.request({
                              url: url + '/v1/article',
                              data: {},
                              method: "get",
                              header: {
                                'content-Type': 'application/json',
                                'authorization': wx.getStorageSync('authorization'),
                                'openid': wx.getStorageSync('openid')
                              },
                              success: function(res) {
                                var list = []
                                list = res.data.data.mpArticleResponses
                                for (var i = 0; i < list.length; i++) {
                                  list[i].image = list[i].image.split(",").slice(0, 3)
                                }
                                for (var j = 0; j < list.length; j++) {
                                  if (list[j].type == 1) {
                                    list[j].ctype = '求助'
                                  } else if (list[j].type == 2) {
                                    list[j].ctype = '闲置'
                                  } else if (list[j].type == 3) {
                                    list[j].ctype = '兼职'
                                  } else if (list[j].type == 4) {
                                    list[j].ctype = '租房'
                                  } else if (list[j].type == 5) {
                                    list[j].ctype = '寻物'
                                  } else if (list[j].type == 6) {
                                    list[j].ctype = '招领'
                                  } else if (list[j].type == 7) {
                                    list[j].ctype = '投稿'
                                  } else if (list[j].type == 8) {
                                    list[j].ctype = '表白'
                                  }
                                }
                                that.setData({
                                  content: list,
                                  jiazai: false
                                })

                              },
                              fail: function(res) {

                              },
                            });
                          },
                          fail: function(res) {

                          },
                        });
                      }
                    },
                    fail: function(res) {

                    },
                  });
                } else if (res.data.data.code == 20001) {
                  wx.request({
                    url: url + '/v1/register',
                    data: {
                      openId: wx.getStorageSync('openid'),
                      headPortrait: wx.getStorageSync('headPortrait'),
                      nickName: wx.getStorageSync('nickName'),
                    },
                    method: 'post',
                    header: {
                      'content-Type': 'application/json'
                    },
                    success: function(res) {
                      wx.request({
                        url: url + '/v1/token/wx',
                        data: {
                          openId: wx.getStorageSync('openid')
                        },
                        method: "POST",
                        header: {
                          'content-Type': 'application/json'
                        },
                        success: function(res) {
                          wx.setStorageSync('nickName', res.data.data.mpUserLoginResponse.nickName);
                          wx.setStorageSync('headPortrait', res.data.data.mpUserLoginResponse.headPortrait);
                          wx.setStorageSync('allid', res.data.data.mpUserLoginResponse.id);
                          wx.setStorageSync('schoolName', res.data.data.mpUserLoginResponse.schoolName);
                          wx.setStorageSync('authorization', res.data.authorization);
                          that.setData({
                            content: '',
                            jiazai: true,
                          })
                          wx.request({
                            url: url + '/v1/article',
                            data: {},
                            method: "get",
                            header: {
                              'content-Type': 'application/json',
                              'authorization': wx.getStorageSync('authorization'),
                              'openid': wx.getStorageSync('openid')
                            },
                            success: function(res) {
                              var list = []
                              list = res.data.data.mpArticleResponses
                              for (var i = 0; i < list.length; i++) {
                                list[i].image = list[i].image.split(",").slice(0, 3)
                              }
                              for (var j = 0; j < list.length; j++) {
                                if (list[j].type == 1) {
                                  list[j].ctype = '求助'
                                } else if (list[j].type == 2) {
                                  list[j].ctype = '闲置'

                                } else if (list[j].type == 3) {
                                  list[j].ctype = '兼职'

                                } else if (list[j].type == 4) {
                                  list[j].ctype = '租房'

                                } else if (list[j].type == 5) {
                                  list[j].ctype = '寻物'

                                } else if (list[j].type == 6) {
                                  list[j].ctype = '招领'

                                } else if (list[j].type == 7) {
                                  list[j].ctype = '投稿'

                                } else if (list[j].type == 8) {
                                  list[j].ctype = '表白'

                                }
                              }

                              that.setData({
                                content: list,
                                jiazai: false
                              })

                            },
                            fail: function(res) {

                            },
                          });
                        },
                        fail: function(res) {

                        },
                      });
                    },
                    fail: function(res) {

                    }
                  })
                }
              },
              fail: function(res) {

              },
            });
          },
          fail: function(res) {

          },
        });

      }
    })

  },

  onPullDownRefresh() {
    var that = this
    var url = wx.getStorageSync('url')
    var authorization = wx.getStorageSync('authorization')
    if (that.data.current == 0) {
      that.setData({
        content: '',
        jiazai: true,
      })
      wx.request({
        url: url + '/v1/article',
        data: {},
        method: "get",
        header: {
          'content-Type': 'application/json',
          'authorization': authorization,
          'openid': wx.getStorageSync('openid')
        },

        success: function(res) {
          var list = []
          list = res.data.data.mpArticleResponses
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",").slice(0, 3)
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'

            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'

            } else if (list[j].type == 4) {
              list[j].ctype = '租房'

            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'

            } else if (list[j].type == 6) {
              list[j].ctype = '招领'

            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'

            } else if (list[j].type == 8) {
              list[j].ctype = '表白'

            }
            that.setData({
              content: list,
              jiazai: false,
            })
            if (res.data.code == 10008) {

              wx.request({
                url: url + '/v1/token/wx',
                data: {
                  openId: wx.getStorageSync('openid')
                },
                method: "POST",
                header: {
                  'content-Type': 'application/json',
                  'openid': wx.getStorageSync('openid'),
                  'authorization': wx.getStorageSync('authorization')
                },
                success: function(res) {
                  wx.setStorageSync('allid', res.data.data.mpUserLoginResponse.id);
                  wx.setStorageSync('nickName', res.data.data.mpUserLoginResponse.nickName);
                  wx.setStorageSync('headPortrait', res.data.data.mpUserLoginResponse.headPortrait);
                  wx.setStorageSync('schoolName', res.data.data.mpUserLoginResponse.schoolName);
                  wx.setStorageSync('authorization', res.data.authorization);
                  that.setData({
                    jiazai: true,
                    content: ''
                  })
                  wx.request({
                    url: url + '/v1/article',
                    data: {},
                    method: "get",
                    header: {
                      'content-Type': 'application/json',
                      'authorization': wx.getStorageSync('authorization'),
                      'openid': wx.getStorageSync('openid')
                    },
                    success: function(res) {
                      var list = []
                      list = res.data.data.mpArticleResponses
                      for (var i = 0; i < list.length; i++) {
                        list[i].image = list[i].image.split(",").slice(0, 3)
                      }
                      for (var j = 0; j < list.length; j++) {
                        if (list[j].type == 1) {
                          list[j].ctype = '求助'
                        } else if (list[j].type == 2) {
                          list[j].ctype = '闲置'
                        } else if (list[j].type == 3) {
                          list[j].ctype = '兼职'
                        } else if (list[j].type == 4) {
                          list[j].ctype = '租房'
                        } else if (list[j].type == 5) {
                          list[j].ctype = '寻物'
                        } else if (list[j].type == 6) {
                          list[j].ctype = '招领'
                        } else if (list[j].type == 7) {
                          list[j].ctype = '投稿'
                        } else if (list[j].type == 8) {
                          list[j].ctype = '表白'
                        }
                      }
                      that.setData({
                        content: list,
                        jiazai: false
                      })

                    },
                    fail: function(res) {},
                  });
                },
                fail: function(res) {},
              });
            }
          }
          that.setData({
            content: list
          })
        },
        fail: function(res) {},
      });
    } else {
      that.setData({
        content: '',
        jiazai: true,
      })
      wx.request({
        url: url + '/v1/article',
        data: {
          type: that.data.current
        },
        method: "get",
        header: {
          'content-Type': 'application/json',
          'authorization': authorization,
          'openid': wx.getStorageSync('openid')
        },
        success: function(res) {
          var list = []
          list = res.data.data.mpArticleResponses
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",").slice(0, 3)
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'

            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'

            } else if (list[j].type == 4) {
              list[j].ctype = '租房'

            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'

            } else if (list[j].type == 6) {
              list[j].ctype = '招领'

            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'

            } else if (list[j].type == 8) {
              list[j].ctype = '表白'

            }
            that.setData({
              content: list,
              jiazai: false
            })
            if (res.data.code == 10008) {
              wx.request({
                url: url + '/v1/token/wx',
                data: {
                  openId: wx.getStorageSync('openid')
                },
                method: "POST",
                header: {
                  'content-Type': 'application/json',
                  'openid': wx.getStorageSync('openid'),
                  'authorization': wx.getStorageSync('authorization')
                },
                success: function(res) {
                  wx.setStorageSync('allid', res.data.data.mpUserLoginResponse.id);
                  wx.setStorageSync('nickName', res.data.data.mpUserLoginResponse.nickName);
                  wx.setStorageSync('headPortrait', res.data.data.mpUserLoginResponse.headPortrait);
                  wx.setStorageSync('schoolName', res.data.data.mpUserLoginResponse.schoolName);
                  wx.setStorageSync('authorization', res.data.authorization);
                  that.setData({
                    content: '',
                    jiazai: true,
                  })
                  wx.request({
                    url: url + '/v1/article',
                    data: {
                      type: that.data.current
                    },
                    method: "get",
                    header: {
                      'content-Type': 'application/json',
                      'authorization': wx.getStorageSync('authorization'),
                      'openid': wx.getStorageSync('openid')
                    },
                    success: function(res) {
                      var list = []
                      list = res.data.data.mpArticleResponses
                      for (var i = 0; i < list.length; i++) {
                        list[i].image = list[i].image.split(",").slice(0, 3)
                      }
                      for (var j = 0; j < list.length; j++) {
                        if (list[j].type == 1) {
                          list[j].ctype = '求助'
                        } else if (list[j].type == 2) {
                          list[j].ctype = '闲置'
                        } else if (list[j].type == 3) {
                          list[j].ctype = '兼职'
                        } else if (list[j].type == 4) {
                          list[j].ctype = '租房'
                        } else if (list[j].type == 5) {
                          list[j].ctype = '寻物'
                        } else if (list[j].type == 6) {
                          list[j].ctype = '招领'
                        } else if (list[j].type == 7) {
                          list[j].ctype = '投稿'
                        } else if (list[j].type == 8) {
                          list[j].ctype = '表白'
                        }
                      }
                      that.setData({
                        content: list,
                        jiazai: false
                      })

                    },
                    fail: function(res) {},
                  });
                },
                fail: function(res) {},
              });
            }
          }
          that.setData({
            content: list
          })
        },
        fail: function(res) {},
      });
    }

    wx.stopPullDownRefresh()

  },
  onChange(e) {
    var that = this
    var url = wx.getStorageSync('url')
    that.setData({
      current: e.detail.key
    })
    if (e.detail.key == 0) {
      // that.setData({
      //   content: '',
      // })
      that.setData({
        jiazai: true
      })
      wx.request({
        url: url + '/v1/article',
        data: {},
        method: "get",
        header: {
          'content-Type': 'application/json',
          'authorization': wx.getStorageSync('authorization'),
          'openid': wx.getStorageSync('openid')
        },
        success: function(res) {
          var list = []
          list = res.data.data.mpArticleResponses
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",").slice(0, 3)
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'
            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'
            } else if (list[j].type == 4) {
              list[j].ctype = '租房'
            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'
            } else if (list[j].type == 6) {
              list[j].ctype = '招领'
            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'
            } else if (list[j].type == 8) {
              list[j].ctype = '表白'
            }
          }
          that.setData({
            content: list,
            jiazai: false
          })

        },
        fail: function(res) {

        },
      });
    } else if (e.detail.key == 0 && that.data.sou){
      that.setData({
        jiazai: true
      })
      wx.request({
        url: url + '/v1/article',
        data: {
          keyword: that.data.sou,
          curPage: that.data.curPage,
        },
        method: "get",
        header: {
          'content-Type': 'application/json',
          'authorization': wx.getStorageSync('authorization'),
          'openid': wx.getStorageSync('openid')
        },
        success: function (res) {
          var list = []
          list = res.data.data.mpArticleResponses
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",").slice(0, 3)
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'
            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'
            } else if (list[j].type == 4) {
              list[j].ctype = '租房'
            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'
            } else if (list[j].type == 6) {
              list[j].ctype = '招领'
            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'
            } else if (list[j].type == 8) {
              list[j].ctype = '表白'
            }
          }
          that.setData({
            content: list,
            jiazai: false
          })

        },
        fail: function (res) {

        },
      });
    } else if (e.detail.key && that.data.sou){
       that.setData({
        jiazai: true
      })
      wx.request({
        url: url + '/v1/article',
        data: {
          keyword: that.data.sou,
          curPage: that.data.curPage,
          type: e.detail.key
        },
        method: "get",
        header: {
          'content-Type': 'application/json',
          'authorization': wx.getStorageSync('authorization'),
          'openid': wx.getStorageSync('openid')
        },
        success: function (res) {
          var list = []
          list = res.data.data.mpArticleResponses
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",").slice(0, 3)
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'
            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'
            } else if (list[j].type == 4) {
              list[j].ctype = '租房'
            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'
            } else if (list[j].type == 6) {
              list[j].ctype = '招领'
            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'
            } else if (list[j].type == 8) {
              list[j].ctype = '表白'
            }
          }
          that.setData({
            content: list,
            jiazai: false
          })

        },
        fail: function (res) {

        },
      });
    }else {
      that.setData({
        content: '',
        jiazai: true
      })
      wx.request({
        url: url + '/v1/article',
        data: {
          type: e.detail.key
        },
        method: "get",
        header: {
          'content-Type': 'application/json',
          'authorization': wx.getStorageSync('authorization'),
          'openid': wx.getStorageSync('openid')
        },
        success: function(res) {
          var list = []
          list = res.data.data.mpArticleResponses
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",").slice(0, 3)
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'
            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'
            } else if (list[j].type == 4) {
              list[j].ctype = '租房'
            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'
            } else if (list[j].type == 6) {
              list[j].ctype = '招领'
            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'
            } else if (list[j].type == 8) {
              list[j].ctype = '表白'
            }
          }
          that.setData({
            content: list,
            jiazai: false
          })
        },
        fail: function(res) {},
      });
    }
  },
  bindKeyInput: function(e) {
    this.setData({
      inputValue: e.detail.value, //将input至与data中的inputValue绑定
    })
  },
  foo: function() {
    if (this.data.inputValue) {
      //Do Something
    } else {
      //Catch Error
    }
    // this.setData({
    //   inputValue: '' //将data的inputValue清空
    // });
    return;
  },
  submit(e) {
    var that = this
    var url = wx.getStorageSync('url')
    var articleId = e.currentTarget.dataset.ids
    if (that.data.inputValue != '') {
      wx.request({
        url: url + '/v1/article/comment',
        data: {
          articleId: articleId,
          content: that.data.inputValue
        },
        method: "post",
        header: {
          'content-Type': 'application/json',
          'authorization': wx.getStorageSync('authorization'),
          'openid': wx.getStorageSync('openid')
        },
        success: function(res) {
          var list = {
            nickName: wx.getStorageSync('nickName'),
            content: that.data.inputValue,
            parentId: 0
          }
          var cc = that.data.content
          for (var i = 0; i < cc.length; i++) {
            if (cc[i].id == articleId) {
              cc[i].commentNumber = cc[i].commentNumber + 1
              cc[i].mpArticleCommentResponses.unshift(list)
            }
          }
          that.setData({
            content: cc,
            inputValue: ''
          })
        },
        fail: function(res) {
        },
      });
    } else {
      that.setData({
        placeholder: "评论不能为空"
      })
    }
  },
  reply: function(e) {
    this.setData({
      placeholder: '回复：',
      id: e.currentTarget.dataset.ids
    })
  },
  details(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/Details/index?id=' + id + "&token=" + wx.getStorageSync('authorization'),
    })
  },
  onShareAppMessage: (res) => {
    var id = res.id
    return {
      title: '蚂蚁大学',
      imageUrl: "../../astatic/zhanshi.png",
      path: '/pages/index/index?pastid=' + id + "&token=" + wx.getStorageSync('authorization'),
      success: function(shareTickets) {
        console.info(shareTickets + '成功');
        // 转发成功
      },
      fail: function(res) {
        console.log(res + '失败');
        // 转发失败
      },

    }
  },
  big(e) {

    var that = this
    var host = that.data.host
    var current = e.currentTarget.dataset.img;
    var ix = e.currentTarget.dataset.ix;
    current = host + current
    var list = []
    list.push(current)
    that.setData({
      ii: list
    })

    wx.previewImage({
      current: that.data.ii,
      urls: that.data.ii // 需要预览的图片http链接列表
    })

  },
  wxSearchInput: function(e) {
    let that = this
    let url = wx.getStorageSync('url');
    let authorization = wx.getStorageSync('authorization');
    var value = e.detail.value
    that.setData({
      sou: value
    })
  },
  bte(e) {
    var that = this
    var url = wx.getStorageSync('url')
    if (that.data.current == 0) {
      wx.request({
        url: url + "/v1/article",
        data: {
          keyword: that.data.sou,
          curPage: that.data.curPage,

        },
        method: "get",
        header: {
          'content-type': 'application/json',
          'authorization': wx.getStorageSync('authorization'),
          'openId': wx.getStorageSync('openid')
        },
        success: function(res) {
          var list = []
          list = res.data.data.mpArticleResponses
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",")
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'

            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'

            } else if (list[j].type == 4) {
              list[j].ctype = '租房'

            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'

            } else if (list[j].type == 6) {
              list[j].ctype = '招领'

            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'

            } else if (list[j].type == 8) {
              list[j].ctype = '表白'

            }
          }
          that.setData({
            content: list
          })
        }
      })
    } else {
      wx.request({
        url: url + "/v1/article",
        data: {
          keyword: that.data.sou,
          curPage: that.data.curPage,
          type: that.data.current
        },
        method: "get",
        header: {
          'content-type': 'application/json',
          'authorization': wx.getStorageSync('authorization'),
          'openId': wx.getStorageSync('openid')
        },
        success: function(res) {
          var list = []
          list = res.data.data.mpArticleResponses
          if(list!=''){
            for (var i = 0; i < list.length; i++) {
              list[i].image = list[i].image.split(",")
            }
            for (var j = 0; j < list.length; j++) {
              if (list[j].type == 1) {
                list[j].ctype = '求助'
              } else if (list[j].type == 2) {
                list[j].ctype = '闲置'

              } else if (list[j].type == 3) {
                list[j].ctype = '兼职'

              } else if (list[j].type == 4) {
                list[j].ctype = '租房'

              } else if (list[j].type == 5) {
                list[j].ctype = '寻物'

              } else if (list[j].type == 6) {
                list[j].ctype = '招领'

              } else if (list[j].type == 7) {
                list[j].ctype = '投稿'

              } else if (list[j].type == 8) {
                list[j].ctype = '表白'

              }
            }
            // that.data.content = list
            that.setData({
              content: list
            })
          }
          
        }
      })
    }

  },
  scrolltolower(e) {
    var that = this
    var url = wx.getStorageSync('url')
    var authorization = wx.getStorageSync('authorization')
    var curPage = that.data.curPage + 1;
    // wx.showToast({
    //         title: "加载中",
    //         duration: 500
    //       })
    wx.request({
      url: url + '/v1/article',
      data: {
        curPage: curPage,
        type: that.data.current
      },
      method: "get",
      header: {
        'content-Type': 'application/json',
        'authorization': authorization,
        'openid': wx.getStorageSync('openid')
      },
      success: function(res) {
        var contnet = that.data.content
        var list = new Array
        list = res.data.data.mpArticleResponses
        if (list != "") {
          for (var i = 0; i < list.length; i++) {
            list[i].image = list[i].image.split(",")
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'

            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'

            } else if (list[j].type == 4) {
              list[j].ctype = '租房'

            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'

            } else if (list[j].type == 6) {
              list[j].ctype = '招领'

            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'

            } else if (list[j].type == 8) {
              list[j].ctype = '表白'

            }
            contnet.push(list[j])
          }

          that.setData({
            content: contnet,
            curPage: curPage,
            bottom: false
          })
        } else {
          that.setData({
            bottom: true
          })
          // wx.showToast({
          //   title: "已经到底了",
          //   duration: 500
          // })
        }
      },
      fail: function(res) {
        // console.log(res)
      },
    });
  }
})